import { requestApi } from '../../api/request'
const app = getApp()
Page({
    data: {
        preloading:true,
        param:{
            action:'cate',
            cate_id:'',
            page:1
        }
    },
    onInit(option){
        // 监听页面加载的生命周期函数
        console.log(option.classname)
        this.data.param.cate_id = option.id
        let param = this.data.param
        this.getdata(param)
        console.log(option.left)
        this.setData({
            scrollleft:option.left,
            pagename:option.classname
        })
    },
    onLoad: function () {
        // 监听页面加载的生命周期函数
    },
    onReady: function() {
        // 监听页面初次渲染完成的生命周期函数
    },
    onShow: function() {
        // 监听页面显示的生命周期函数
    },
    onHide: function() {
        // 监听页面隐藏的生命周期函数
    },
    onUnload: function() {
        // 监听页面卸载的生命周期函数
    },
    onPullDownRefresh: function() {
        // 监听用户下拉动作
    },
    onReachBottom: function() {
        // 上拉触底
        let page = this.data.param.page
        page++
        this.data.param.page = page
        let param = this.data.param
        console.log(param)
        requestApi(param).then(
            res => {
                // console.log(res)
                let newslistitem = res.data.list
                // console.log(newslistitem)
                let newslist = this.data.newslist.concat(newslistitem)
                // console.log(newslist)
                this.setData({
                    newslist
                })
            }
        )
    },
    onShareAppMessage: function () {
        // 用户点击右上角转发
    },
    getdata(param){
        requestApi(param).then(
            res => {
                console.log(res)
                let newslist = res.data.list
                let site = res.data.site
                this.setData({
                    preloading:false,
                    newslist,
                })
                app.getTdk(site)
            }
        )
    }
});